<?php
namespace Admin\Controller;
use Common\Controller\AdminController;

class NodeController extends AdminController{

	public function index(){
		$list = $this->getList('id,pid,title,name,sort,status', 'node', null, 'sort desc,id asc');
		$this->sortNode($list, $result);
		$this->assign('list', $result);
		$this->display();
	}

	public function add(){
		if(IS_POST){
			$result = $this->updateData($_POST, 'node');
			$this->returnResult($result);
		}else{
			$list = $this->getList('id,title,pid', 'node', 'status=1', 'sort desc,id asc');
			$this->sortNode($list, $result);
			$this->assign('nodeList', $result);
			$this->display();
		}
	}

	public function edit(){
		if(IS_POST){
			$result = $this->updateData($_POST, 'node', 2);
			$this->returnResult($result);
		}else{
			$info = $this->getInfo('id,pid,title,name,status,sort', 'node', 'id=' . I('get.id', 0, 'intval'));
			$this->assign('info', $info);
			$list = $this->getList('id,title,pid', 'node', 'status=1', 'sort desc,id asc');
			$this->sortNode($list, $result);
			$this->assign('nodeList', $result);
			$this->display('add');
		}
	}

	public function del(){
		$result = $this->deleteData('id=' . I('get.id', 0, 'intval'), 'node');
		$this->returnResult($result);
	}
}